package com.acwing.chapter3;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;

/**
 * @author anan
 * @create 2021-07-28 21:04
 */
class Pair{
    int first;
    int second;

    Pair(int first, int second) {
        this.first = first;
        this.second = second;
    }
}
public class Qujianhe {

    public static int unique(ArrayList<Integer> adds){
        int j = 0;
        for (int i = 0; i < adds.size(); i++) {
            if (i == 0 || !adds.get(i).equals(adds.get(i - 1))){
                adds.set(j, adds.get(i));
                j++;
            }
        }
        return j;
    }

    public static int find(ArrayList<Integer> adds, int x){
        int l = 0;
        int r = adds.size() - 1;
        while (l < r) {
            int mid = l + r >> 1;
            if (adds.get(mid) >= x) r = mid;
            else l = mid + 1;
        }
        return r + 1;
    }


    public static void main(String[] args) throws IOException {
        final int N = 300010;
        ArrayList<Integer> adds = new ArrayList<>(); //adds表示所有要用到的下标
        ArrayList<Pair> query = new ArrayList<>();
        ArrayList<Pair> add = new ArrayList<>();
        int[] a = new int[N];
        int[] s = new int[N];


        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String[] str1 = reader.readLine().split(" ");
        int n = Integer.parseInt(str1[0]);
        int m = Integer.parseInt(str1[1]);

        int x, c, l, r;

        for (int i = 0; i < n; i++) {
            String[] str2 = reader.readLine().split(" ");
            x = Integer.parseInt(str2[0]);
            c = Integer.parseInt(str2[1]);
            adds.add(x);
            add.add(new Pair(x,c));
        }

        for (int i = 0; i < m; i++) {
            String[] str3 = reader.readLine().split(" ");
            l = Integer.parseInt(str3[0]);
            r = Integer.parseInt(str3[1]);
            adds.add(l);
            adds.add(r);
            query.add(new Pair(l,r));
        }

        Collections.sort(adds);
        int unique = unique(adds);
        adds.subList(0, unique);

        for (int i = 0; i < n; i++) {
            x= find(adds, add.get(i).first);
            a[x] += add.get(i).second;
        }

        for (int i = 0; i < adds.size(); i++) {
            s[i + 1] = s[i] + a[i + 1];
        }


        for (int i = 0; i < m; i++) {
            int start = find(adds, query.get(i).first);
            int end = find(adds, query.get(i).second);
            System.out.println(s[end] - s[start - 1]);

        }


    }
}